package org.stwy.report;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.stwy.lease.contract.ContractAssetEntity;
import org.stwy.lease.contract.ContractEntity;
import org.stwy.lease.rent.RentEntity;
import org.stwy.pro.asset.AssetEntity;

import com.github.abel533.echarts.Option;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Magic;
import com.github.abel533.echarts.code.Orient;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.data.PieData;
import com.github.abel533.echarts.feature.MagicType;
import com.github.abel533.echarts.json.GsonUtil;
import com.github.abel533.echarts.series.Pie;
import com.rap.common.report.RapReportService;
import com.rap.common.report.ReportModel;
import com.rap.common.table.CellModel;
import com.rap.common.table.CellModel.CellStyle;
import com.rap.common.table.RowModel;
import com.rap.common.table.TableModel;
import com.rap.common.utils.DateUtil;
import com.rap.common.utils.StringUtil;
import com.rap.frame.enumdata.EnumDataSubEntity;
import com.rap.frame.enumdata.EnumDataUtils;

@Service(value = "stwyReportService")
public class StwyReportService extends RapReportService{
	@Autowired
	private StwyReportDAO stwyReportDAO;
	
	public ReportModel getReport(Map parameterMap, String reportName) {
		ReportModel reportModel=null;
		if("report1".equals(reportName)){
			reportModel = getReport1(parameterMap);
		}else if("report2".equals(reportName)){
			reportModel = getReport2(parameterMap);
		}else if("report3".equals(reportName)){
			reportModel = getReport3(parameterMap);
		}else if("report4".equals(reportName)){
			reportModel = getReport4(parameterMap);
		}else if("report5".equals(reportName)){
			reportModel = getReport5(parameterMap);
		}else if("report6".equals(reportName)){
			reportModel = getReport6(parameterMap);
		}else if("report7".equals(reportName)){
			reportModel = getReport7(parameterMap);
		}else if("report9".equals(reportName)){
			reportModel = getReport9(parameterMap);
		}
		return reportModel;
	}
	/**
	 * 收费汇总表
	 * @param parameterMap
	 * @return
	 */
	private ReportModel getReport9(Map parameterMap) {
		/*String dateStr= ((String[])parameterMap.get("reportDate"))[0];
		String title = "收费汇总表";
		int colNum = 9;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).width(1000).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		//题注 日期
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateStr).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel().addCell(new CellModel("编号").cellStyle(CellStyle.head).width(50));
		row.addCell(new CellModel("物业名称").cellStyle(CellStyle.head));
		row.addCell(new CellModel("位置").cellStyle(CellStyle.head));
		row.addCell(new CellModel("用途").cellStyle(CellStyle.head));
		row.addCell(new CellModel("租赁期限").cellStyle(CellStyle.head));
		row.addCell(new CellModel("物业资产(㎡)").cellStyle(CellStyle.head));
		row.addCell(new CellModel("政府指导价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("市场价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("备注").cellStyle(CellStyle.head));
		headerList.add(row);
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		List<ContractAssetEntity> list = this.stwyReportDAO.findBillsByMonth(dateStr);
		int i =0;
		String groupOne="";
		String groupTwo="";
		double groupOnetTotal = 0;
		double groupOnetNull = 0;
		double groupTwotTotal = 0;
		double groupTwotNull = 0;
		double allTotal=0;
		double allNull=0;
		Map hashAdd = new HashMap();
		for(ContractAssetEntity data : list){
			i = i+1;
			//分类统计
			if(!groupTwo.equals(data.getAsset().getGroupTwo())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("小计"));
					row.addCell(new CellModel(EnumDataUtils.getEnumValue(groupTwo, "stwy_groupTwo")+"：物业面积合计").cellClass("center").colspan(4));
					row.addCell(new CellModel(groupTwotTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupTwotNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupTwo=data.getAsset().getGroupTwo();
			}
			if(!groupOne.equals(data.getAsset().getGroupOne())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("合计"));
					String name = EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne");
					row.addCell(new CellModel(""
					+(name==null?"":name+"：物业面积合计")).cellClass("center").colspan(4));
					row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupOnetTotal = 0;
				groupOnetNull = 0;
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupOne=data.getAsset().getGroupOne();
				groupTwo=data.getAsset().getGroupTwo();
			}
			//表格填充
			row = new RowModel();
			row.addCell(new CellModel(i).cellClass("center"));
			row.addCell(new CellModel(data.getAsset().getTheName()));
			row.addCell(new CellModel(data.getAsset().getAddress()));
			row.addCell(new CellModel(EnumDataUtils.getEnumValue(data.getAsset().getUsefor(), "stwy_usefor")));
			row.addCell(new CellModel(data.getContract().getBeginDate()+"~"+data.getContract().getEndDate()));
			row.addCell(new CellModel(data.getAsset().getArea()).cellClass("rap-td-number"));
			double gov = data.getContract().getGovPrice()==null?0:data.getContract().getGovPrice();
			row.addCell(new CellModel(gov));
			row.addCell(new CellModel(data.getContract().getMarketPrice()));
			row.addCell(new CellModel(data.getContract().getRemark()));
			dataList.add(row);
			
			groupOnetTotal=groupOnetTotal+data.getAsset().getArea();
			groupTwotTotal=groupTwotTotal+data.getAsset().getArea();
			groupOnetNull=gov;
			groupTwotNull=gov;
			allTotal = allTotal+data.getAsset().getArea();
			allNull = allNull + gov;
		}
		row = new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel("合计"));
		String name = EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne");
		row.addCell(new CellModel(""
		+(name==null?"":name+"：物业面积合计")).cellClass("center").colspan(4));
		row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
		row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
		row.addCell(new CellModel("").colspan(2));
		dataList.add(row);
		
		//总合计
		row = new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel("合计"));
		row.addCell(new CellModel("物业面积（总计）").cellClass("center").colspan(4));
		row.addCell(new CellModel(allTotal).cellClass("rap-td-number"));
		row.addCell(new CellModel(allNull).cellClass("rap-td-number"));
		row.addCell(new CellModel("").colspan(2));
		dataList.add(row);
		
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;*/
		return null;
	}
	String names1[] = {
			"达到政府指导价100%",
			"达到政府指导价80% 以上",
			"未达到政府指导价80%",
			"无政府指导价（含淡水）",
			"自  用"
	};
	String names2[] = {
			"已租",
			"自用",
			"空置",
			"不可出租"
	};
	
	public Map getReport8(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		
		Map map = new HashMap();
		List dataList1 = new ArrayList();
		List dataList2 = new ArrayList();
		
		List<ContractEntity> contractList = this.stwyReportDAO.findContracts(reportDate);
		List<AssetEntity> assetList = this.stwyReportDAO.findAllAssets(reportDate);
		double value1 = 0,value2 = 0,value3 = 0,value4 = 0,value5 = 0;
		double percent1 = 0,percent2 = 0,percent3 = 0,percent4 = 0,percent5 = 0;
		int count1 = 0,count2 = 0,count3 = 0,count4 = 0,count5 = 0;
		double totalArea=0;
		for(ContractEntity contract : contractList){
			totalArea=totalArea+contract.getArea();
			
			Double gov = contract.getGovPrice();
			Double price = contract.getPrice();
			if(gov==null||gov<=0){
				value4 = value4+contract.getArea();
				count4++;
				continue;
			}
			double result = price/gov;
			if(result>=1){
				value1 = value1+contract.getArea();
				count1++;
			}else if(result>=0.8){
				value2 = value2+contract.getArea();
				count2++;
			}else if(result<=0.8){
				value3 = value3+contract.getArea();
				count3++;
			}
		}
		double rent = 0,self = 0,canNotRent = 0,nullArea = 0;
		double total = 0;
		for(AssetEntity asset : assetList){
			total = total + asset.getArea();
			//自用
			if(AssetEntity.ASSET_STATUS_SELF.equals(asset.getAssetState())){
				value5 = value5+asset.getArea();
				count5++;
				totalArea=totalArea+asset.getArea();
				
				self = self + asset.getArea();
			}else if(AssetEntity.ASSET_STATUS_NULL.equals(asset.getAssetState())){
				nullArea = nullArea + asset.getArea();
			}else if(AssetEntity.ASSET_STATUS_RENT.equals(asset.getAssetState())){
				rent = rent + asset.getArea();
			}else if(AssetEntity.ASSET_STATUS_CANNOTRENT.equals(asset.getAssetState())){
				canNotRent = canNotRent + asset.getArea();
			}
		}
		percent1=value1/totalArea*100;
		percent2=value2/totalArea*100;
		percent3=value3/totalArea*100;
		percent4=value4/totalArea*100;
		percent5=value5/totalArea*100;
		Map map1 = new HashMap();
		map1.put("rowNum",1);
		map1.put("name",names1[0]);
		map1.put("value",value1);
		map1.put("percent",percent1);
		map1.put("count",count1);
		dataList1.add(map1);
		
		Map map2 = new HashMap();
		map2.put("rowNum",2);
		map2.put("name",names1[1]);
		map2.put("value",value2);
		map2.put("percent",percent2);
		map2.put("count",count2);
		dataList1.add(map2);
		
		Map map3 = new HashMap();
		map3.put("rowNum",3);
		map3.put("name",names1[2]);
		map3.put("value",value3);
		map3.put("percent",percent3);
		map3.put("count",count3);
		dataList1.add(map3);
		
		Map map4 = new HashMap();
		map4.put("rowNum",4);
		map4.put("name",names1[3]);
		map4.put("value",value4);
		map4.put("percent",percent4);
		map4.put("count",count4);
		dataList1.add(map4);
		
		Map map5 = new HashMap();
		map5.put("rowNum",5);
		map5.put("name",names1[4]);
		map5.put("value",value5);
		map5.put("percent",percent5);
		map5.put("count",count5);
		dataList1.add(map5);
		
		Map map21 = new HashMap();
		map21.put("name",names2[0]);
		map21.put("value",rent);
		dataList2.add(map21);
		
		Map map22 = new HashMap();
		map22.put("name",names2[1]);
		map22.put("value",self);
		dataList2.add(map22);
		
		Map map23 = new HashMap();
		map23.put("name",names2[2]);
		map23.put("value",nullArea);
		dataList2.add(map23);
		
		Map map24 = new HashMap();
		map24.put("name",names2[3]);
		map24.put("value",canNotRent);
		dataList2.add(map24);
		
		TableModel table1 = this.getTable1(dataList1,totalArea,reportDate);
		TableModel table2 = this.getTable2(dataList2,total);
		JSONObject chart1 = this.getChart1(dataList1);
		JSONObject chart2 = this.getChart2(dataList2);
		
		map.put("table1", table1);
		map.put("table2", table2);
		map.put("chart1", chart1);
		map.put("chart2", chart2);
		return map;
	}
	private JSONObject getChart2(List dataList) {
		/************图表2*****************/
		String echartTitle = "委托物业现状图";
		
		Option option2 = new Option();
		//设置标题
		option2.title().text(echartTitle).x("center");
		//设置工具栏
		option2.toolbox().show(true).feature(Tool.dataView ,Tool.saveAsImage);
		//设置图例
		option2.legend().data(names2).orient(Orient.vertical).x("left");
		//设置数据 会自动索引到图例
		option2.series(getPie(dataList));
		//设置提示
		option2.tooltip().show(true);
		String jsonStr = GsonUtil.format(option2);
		return JSONObject.fromObject(jsonStr);
	}
	private JSONObject getChart1(List dataList) {
		/************图表1*****************/
		String echartTitle = "受托物业面积与达到政府指导价所占比较图表";
		Option option1 = new Option();
		//设置标题
		option1.title().text(echartTitle).x("center");
		//设置工具栏
		option1.toolbox().show(true).feature(Tool.dataView ,Tool.saveAsImage);
		//设置图例
		option1.legend().data(names1).orient(Orient.vertical).x("left");
		//设置数据 会自动索引到图例
		option1.series(getPie(dataList));
		//设置提示
		option1.tooltip().show(true);
		String jsonStr = GsonUtil.format(option1);
		return JSONObject.fromObject(jsonStr);
	}
	private TableModel getTable2(List<Map> dataList, double total) {
		TableModel table = new TableModel();
		List<RowModel> rowList = new ArrayList<RowModel>();
		RowModel row =  new RowModel().addCell(new CellModel("委托物业现状图").cellStyle(CellStyle.title).colspan(5));
		rowList.add(row);
		row =  new RowModel().addCell(new CellModel("单位：㎡").cellStyle(CellStyle.tag).colspan(5));
		rowList.add(row);
		row =  new RowModel().addCell(new CellModel("物业总面积").cellStyle(CellStyle.head).rowspan(2)).addCell(new CellModel("可出租物业").cellStyle(CellStyle.head).colspan(3)).addCell(new CellModel("不可出租物业").cellStyle(CellStyle.head).rowspan(2));
		rowList.add(row);
		row =  new RowModel().addCell(new CellModel("已租").cellStyle(CellStyle.head)).addCell(new CellModel("自用").cellStyle(CellStyle.head)).addCell(new CellModel("空置").cellStyle(CellStyle.head));
		rowList.add(row);
		row =  new RowModel().addCell(new CellModel(total).cellClass("rap-td-number"));
		for(Map map : dataList){
			row.addCell(new CellModel(map.get("value")).cellStyle(CellStyle.normal).cellClass("rap-td-number"));
		}
		rowList.add(row);
		table.setRowList(rowList);
		return table;
	}
	private TableModel getTable1(List<Map> dataList, double totalArea,Date reportDate) {
		TableModel table = new TableModel();
		List<RowModel> rowList = new ArrayList<RowModel>();
		//
		RowModel row =  new RowModel().addCell(new CellModel("受托物业面积与达到政府指导价所占比较图表").cellStyle(CellStyle.title).colspan(5));
		rowList.add(row);
		row =  new RowModel().addCell(new CellModel("日期："+DateUtil.dateToString(reportDate)).cellStyle(CellStyle.tag).colspan(5));
		rowList.add(row);
		row =  new RowModel().addCell(new CellModel("序号").cellStyle(CellStyle.head))
				.addCell(new CellModel("项目").cellStyle(CellStyle.head))
				.addCell(new CellModel("物业（㎡）").cellStyle(CellStyle.head))
				.addCell(new CellModel("占总物业面积（%）").cellStyle(CellStyle.head))
				.addCell(new CellModel("项").cellStyle(CellStyle.head));
		rowList.add(row);
		int count=0;
		for(Map map : dataList){
			row =  new RowModel();
			row.addCell(new CellModel(map.get("rowNum")).cellStyle(CellStyle.normal));
			row.addCell(new CellModel(map.get("name")).cellStyle(CellStyle.normal));
			row.addCell(new CellModel(map.get("value")).cellStyle(CellStyle.normal).cellClass("rap-td-number"));
			row.addCell(new CellModel(map.get("percent")).cellStyle(CellStyle.normal).cellClass("rap-td-number"));
			row.addCell(new CellModel(map.get("count")).cellStyle(CellStyle.normal));
			rowList.add(row);
			count=count+(Integer)map.get("count");
		}
		row =  new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel(" ").cellStyle(CellStyle.normal));
		row.addCell(new CellModel("合计").cellStyle(CellStyle.normal));
		row.addCell(new CellModel(totalArea).cellStyle(CellStyle.normal).cellClass("rap-td-number"));
		row.addCell(new CellModel("100%").cellStyle(CellStyle.normal));
		row.addCell(new CellModel(count).cellStyle(CellStyle.normal));
		rowList.add(row);
		table.setRowList(rowList);
		return table;
	}
	
	public Pie getPie(List dataList) {
		Pie pie = new Pie().name("");
		pie.radius("50%").center("50%",170);
		Iterator<Map> it = dataList.iterator();
		while (it.hasNext()) {
			Map<String,String> map = it.next();
			pie.data().add(new PieData(map.get("name"), map.get("value")));
		} 
        return pie;
    }
	/**
	 * 未来三个月内到期的合同
	 * @param parameterMap
	 * @return
	 */
	private ReportModel getReport7(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		String title = "未来三个月内到期的合同";
		String dateTag = "日期："+DateUtil.dateToString(reportDate);
		int colNum = 9;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).width(1000).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		//题注 日期
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateTag).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel().addCell(new CellModel("编号").cellStyle(CellStyle.head).width(50));
		row.addCell(new CellModel("物业名称").cellStyle(CellStyle.head));
		row.addCell(new CellModel("位置").cellStyle(CellStyle.head));
		row.addCell(new CellModel("用途").cellStyle(CellStyle.head));
		row.addCell(new CellModel("租赁期限").cellStyle(CellStyle.head));
		row.addCell(new CellModel("物业资产(㎡)").cellStyle(CellStyle.head));
		row.addCell(new CellModel("政府指导价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("市场价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("备注").cellStyle(CellStyle.head));
		headerList.add(row);
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		List<ContractAssetEntity> list = this.stwyReportDAO.find3MonthsEndContracts(reportDate);
		int i =0;
		String groupOne="";
		String groupTwo="";
		double groupOnetTotal = 0;
		double groupOnetNull = 0;
		double groupTwotTotal = 0;
		double groupTwotNull = 0;
		double allTotal=0;
		double allNull=0;
		Map hashAdd = new HashMap();
		for(ContractAssetEntity data : list){
			i = i+1;
			//分类统计
			if(!groupTwo.equals(data.getAsset().getGroupTwo())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("小计"));
					row.addCell(new CellModel(EnumDataUtils.getEnumValue(groupTwo, "stwy_groupTwo")+"：物业面积合计").cellClass("center").colspan(4));
					row.addCell(new CellModel(groupTwotTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupTwotNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupTwo=data.getAsset().getGroupTwo();
			}
			if(!groupOne.equals(data.getAsset().getGroupOne())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("合计"));
					String name = EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne");
					row.addCell(new CellModel(""
					+(name==null?"":name+"：物业面积合计")).cellClass("center").colspan(4));
					row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupOnetTotal = 0;
				groupOnetNull = 0;
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupOne=data.getAsset().getGroupOne();
				groupTwo=data.getAsset().getGroupTwo();
			}
			//表格填充
			row = new RowModel();
			row.addCell(new CellModel(i).cellClass("center"));
			row.addCell(new CellModel(data.getAsset().getTheName()));
			row.addCell(new CellModel(data.getAsset().getAddress()));
			row.addCell(new CellModel(EnumDataUtils.getEnumValue(data.getAsset().getUsefor(), "stwy_usefor")));
			row.addCell(new CellModel(data.getContract().getBeginDate()+"~"+data.getContract().getEndDate()));
			row.addCell(new CellModel(data.getAsset().getArea()).cellClass("rap-td-number"));
			double gov = data.getContract().getGovPrice()==null?0:data.getContract().getGovPrice();
			row.addCell(new CellModel(gov));
			row.addCell(new CellModel(data.getContract().getMarketPrice()));
			row.addCell(new CellModel(data.getContract().getRemark()));
			dataList.add(row);
			
			groupOnetTotal=groupOnetTotal+data.getAsset().getArea();
			groupTwotTotal=groupTwotTotal+data.getAsset().getArea();
			groupOnetNull=gov;
			groupTwotNull=gov;
			allTotal = allTotal+data.getAsset().getArea();
			allNull = allNull + gov;
		}
		row = new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel("合计"));
		String name = EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne");
		row.addCell(new CellModel(""
		+(name==null?"":name+"：物业面积合计")).cellClass("center").colspan(4));
		row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
		row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
		row.addCell(new CellModel("").colspan(2));
		dataList.add(row);
		
		//总合计
		row = new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel("合计"));
		row.addCell(new CellModel("物业面积（总计）").cellClass("center").colspan(4));
		row.addCell(new CellModel(allTotal).cellClass("rap-td-number"));
		row.addCell(new CellModel(allNull).cellClass("rap-td-number"));
		row.addCell(new CellModel("").colspan(2));
		dataList.add(row);
		
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;
	}

	private ReportModel getReport6(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		String title = "深投发展"+DateUtil.formatDate(reportDate, "yyyy年MM月")+"经营情况综述";
		String dateTag = "日期："+DateUtil.getDate();
		int colNum = 10;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).width(1000).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		
		//题注
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateTag).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		//一、物业出租情况
		row = new RowModel().rowStyle("font-weight:bold;font-size:20px;").addCell(new CellModel("一、物业出租情况").colspan(colNum).cellStyle(CellStyle.normal));
		tagList.add(row);
		//1、委托物业现状（面积：平方米）
		row = new RowModel().rowStyle("font-weight:bold;").addCell(new CellModel("1、委托物业现状（面积：平方米）").colspan(colNum).cellStyle(CellStyle.normal));
		tagList.add(row);
	
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel().addCell(new CellModel("按组分类").cellStyle(CellStyle.head).width(100).rowspan(3).colspan(2));
		row.addCell(new CellModel("物业总面积").cellStyle(CellStyle.head).width(100).rowspan(2));
		row.addCell(new CellModel("可出租物业").cellStyle(CellStyle.head).width(300).colspan(3));
		row.addCell(new CellModel("不可出租物业").cellStyle(CellStyle.head).width(300).colspan(3).rowspan(2));
		row.addCell(new CellModel("出租率（%）").cellStyle(CellStyle.head).width(200).rowspan(2));
		headerList.add(row);
		
		row = new RowModel();
		row.addCell(new CellModel("出租物业").cellStyle(CellStyle.head).width(200).colspan(2));
		row.addCell(new CellModel("空置物业").cellStyle(CellStyle.head).width(100).rowspan(2));
		headerList.add(row);
		
		row = new RowModel().addCell(new CellModel("=可出租+不可出租").cellStyle(CellStyle.head).width(100));
		row.addCell(new CellModel("已租").cellStyle(CellStyle.head).width(100));
		row.addCell(new CellModel("自用").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("问题物业").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("未建立合同物业").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("其他").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("=出租物业/（出租物业+空置）").cellStyle(CellStyle.head).width(100));
		headerList.add(row);
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		Date firstDate = DateUtil.getFirstDayOfMonth(reportDate);
		Date lastDate = DateUtil.getLastDayOfMonth(reportDate);
		List<RentEntity> list = this.stwyReportDAO.findRentByDate(firstDate,lastDate);
		
		
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;
	}

	private ReportModel getReport5(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		String title = DateUtil.formatDate(reportDate, "yyyy年MM月")+"委托物业不可出租情况明细表";
		String dateTag = "日期："+DateUtil.dateToString(reportDate);
		int colNum = 8;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).width(1000).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		//题注 日期
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateTag).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel().addCell(new CellModel("编号").cellStyle(CellStyle.head).width(50));
		row.addCell(new CellModel("物业名称").cellStyle(CellStyle.head));
		row.addCell(new CellModel("位置").cellStyle(CellStyle.head));
		row.addCell(new CellModel("用途").cellStyle(CellStyle.head));
		row.addCell(new CellModel("物业面积(㎡)").cellStyle(CellStyle.head));
		row.addCell(new CellModel("不可出租(㎡)").cellStyle(CellStyle.head));
		row.addCell(new CellModel("不可出租原因").cellStyle(CellStyle.head));
		row.addCell(new CellModel("房产证号").cellStyle(CellStyle.head));
		headerList.add(row);
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		List<AssetEntity> list = this.stwyReportDAO.findAssets(reportDate,AssetEntity.ASSET_STATUS_CANNOTRENT);
		int i =0;
		String groupOne="";
		String groupTwo="";
		double groupOnetTotal = 0;
		double groupOnetNull = 0;
		double groupTwotTotal = 0;
		double groupTwotNull = 0;
		double allTotal=0;
		double allNull=0;
		Map hashAdd = new HashMap();
		for(AssetEntity data : list){
			i = i+1;
			//分类统计
			if(!groupTwo.equals(data.getGroupTwo())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("小计"));
					row.addCell(new CellModel(EnumDataUtils.getEnumValue(groupTwo, "stwy_groupTwo")+"：物业不可出租面积合计").cellClass("center").colspan(3));
					row.addCell(new CellModel(groupTwotTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupTwotNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupTwo=data.getGroupTwo();
			}
			if(!groupOne.equals(data.getGroupOne())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("合计"));
					row.addCell(new CellModel(""+EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne")+"：物业不可出租面积合计").cellClass("center").colspan(3));
					row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupOnetTotal = 0;
				groupOnetNull = 0;
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupOne=data.getGroupOne();
				groupTwo=data.getGroupTwo();
			}
			//表格填充
			row = new RowModel();
			row.addCell(new CellModel(i).cellClass("center"));
			row.addCell(new CellModel(data.getTheName()));
			row.addCell(new CellModel(data.getAddress()));
			row.addCell(new CellModel(EnumDataUtils.getEnumValue(data.getUsefor(), "stwy_usefor")));
			row.addCell(new CellModel(data.getProperty().getTotalArea()).cellClass("rap-td-number"));
			row.addCell(new CellModel(data.getArea()).cellClass("rap-td-number"));
			row.addCell(new CellModel(EnumDataUtils.getEnumValue(data.getCanNotRentType(), "stwy_canNotRentType")+"："+data.getReason()));
			row.addCell(new CellModel(data.getHouseCert()));
			dataList.add(row);
			
			if(!hashAdd.containsKey(data.getProperty().getTheCode())){
				groupOnetTotal=groupOnetTotal+data.getProperty().getTotalArea();
				groupTwotTotal=groupTwotTotal+data.getProperty().getTotalArea();
				hashAdd.put(data.getProperty().getTheCode(), data.getProperty().getTotalArea());
			}
			groupOnetNull=groupOnetNull+data.getArea();
			groupTwotNull=groupTwotNull+data.getArea();
			allTotal = allTotal+data.getProperty().getTotalArea();
			allNull = allNull + data.getArea();
		}
		row = new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel("合计"));
		row.addCell(new CellModel(""+EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne")+"：不可出租面积合计").cellClass("center").colspan(3));
		row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
		row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
		row.addCell(new CellModel("").colspan(2));
		dataList.add(row);
		
		//总合计
		row = new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel("合计"));
		row.addCell(new CellModel("不可出租面积合计").cellClass("center").colspan(3));
		row.addCell(new CellModel(allTotal).cellClass("rap-td-number"));
		row.addCell(new CellModel(allNull).cellClass("rap-td-number"));
		row.addCell(new CellModel("").colspan(2));
		dataList.add(row);
		
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;
	}
	/**
	 * 空置物业明细表
	 * @param parameterMap
	 * @return
	 */
	private ReportModel getReport4(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		String title = DateUtil.formatDate(reportDate, "yyyy年MM月")+"委托物业空置情况明细表";
		String dateTag = "日期："+DateUtil.dateToString(reportDate);
		int colNum = 8;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).width(1000).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		//题注 日期
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateTag).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel().addCell(new CellModel("编号").cellStyle(CellStyle.head).width(50));
		row.addCell(new CellModel("物业名称").cellStyle(CellStyle.head));
		row.addCell(new CellModel("位置").cellStyle(CellStyle.head).width(200));
		row.addCell(new CellModel("用途").cellStyle(CellStyle.head));
		row.addCell(new CellModel("物业面积(㎡)").cellStyle(CellStyle.head));
		row.addCell(new CellModel("空置(㎡)").cellStyle(CellStyle.head));
		row.addCell(new CellModel("备注").cellStyle(CellStyle.head));
		row.addCell(new CellModel("房产证号").cellStyle(CellStyle.head));
		headerList.add(row);
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		List<AssetEntity> list = this.stwyReportDAO.findAssets(reportDate,AssetEntity.ASSET_STATUS_NULL);
		int i =0;
		String groupOne="";
		String groupTwo="";
		double groupOnetTotal = 0;
		double groupOnetNull = 0;
		double groupTwotTotal = 0;
		double groupTwotNull = 0;
		Map hashAdd = new HashMap();
		for(AssetEntity data : list){
			i = i+1;
			//分类统计
			if(!groupTwo.equals(data.getGroupTwo())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("小计"));
					row.addCell(new CellModel(EnumDataUtils.getEnumValue(groupTwo, "stwy_groupTwo")+"：物业空置面积合计").cellClass("center").colspan(3));
					row.addCell(new CellModel(groupTwotTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupTwotNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupTwo=data.getGroupTwo();
			}
			if(!groupOne.equals(data.getGroupOne())){
				if(i!=1){
					row = new RowModel().rowStyle("font-weight:bold;");
					row.addCell(new CellModel("合计"));
					row.addCell(new CellModel(""+EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne")+"：物业空置面积合计").cellClass("center").colspan(3));
					row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
					row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
					row.addCell(new CellModel("").colspan(2));
					dataList.add(row);
				}
				groupOnetTotal = 0;
				groupOnetNull = 0;
				groupTwotTotal = 0;
				groupTwotNull = 0;
				groupOne=data.getGroupOne();
				groupTwo=data.getGroupTwo();
			}
			//表格填充
			row = new RowModel();
			row.addCell(new CellModel(i).cellClass("center"));
			row.addCell(new CellModel(data.getTheName()));
			row.addCell(new CellModel(data.getAddress()));
			row.addCell(new CellModel(EnumDataUtils.getEnumValue(data.getUsefor(), "stwy_usefor")));
			row.addCell(new CellModel(data.getProperty().getTotalArea()).cellClass("rap-td-number"));
			row.addCell(new CellModel(data.getArea()).cellClass("rap-td-number"));
			row.addCell(new CellModel(data.getReason()));
			row.addCell(new CellModel(data.getHouseCert()));
			dataList.add(row);
			
			if(!hashAdd.containsKey(data.getProperty().getTheCode())){
				groupOnetTotal=groupOnetTotal+data.getProperty().getTotalArea();
				groupTwotTotal=groupTwotTotal+data.getProperty().getTotalArea();
				hashAdd.put(data.getProperty().getTheCode(), data.getProperty().getTotalArea());
			}
			groupOnetNull=groupOnetNull+data.getArea();
			groupTwotNull=groupTwotNull+data.getArea();
			
		}
		row = new RowModel().rowStyle("font-weight:bold;");
		row.addCell(new CellModel("合计"));
		row.addCell(new CellModel(""+EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne")+"：物业空置面积合计").cellClass("center").colspan(3));
		row.addCell(new CellModel(groupOnetTotal).cellClass("rap-td-number"));
		row.addCell(new CellModel(groupOnetNull).cellClass("rap-td-number"));
		row.addCell(new CellModel("").colspan(2));
		dataList.add(row);
		
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;
	}
	/**
	 * 获取租金收缴明细
	 * @param parameterMap
	 * @return
	 */
	private ReportModel getReport3(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		String title = DateUtil.formatDate(reportDate, "yyyy年MM月")+"委托物业租金收缴明细";
		String dateTag = "统计日期："+DateUtil.getDate();
		int colNum = 10;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		
		//题注
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateTag).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel();
		row.addCell(new CellModel("合同编号").cellStyle(CellStyle.head));
		row.addCell(new CellModel("承租单位").cellStyle(CellStyle.head));
		row.addCell(new CellModel("租赁期限").cellStyle(CellStyle.head));
		row.addCell(new CellModel("出租总面积").cellStyle(CellStyle.head));
		row.addCell(new CellModel("租金单价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("合同规定本月租金").cellStyle(CellStyle.head));
		row.addCell(new CellModel("应缴日期").cellStyle(CellStyle.head));
		row.addCell(new CellModel("实际收缴日期").cellStyle(CellStyle.head));
		row.addCell(new CellModel("实际收缴").cellStyle(CellStyle.head));
		row.addCell(new CellModel("补交租金").cellStyle(CellStyle.head));
		row.addCell(new CellModel("预付租金").cellStyle(CellStyle.head));
		row.addCell(new CellModel("结余").cellStyle(CellStyle.head));
		row.addCell(new CellModel("保证金本次交").cellStyle(CellStyle.head));
		row.addCell(new CellModel("备注").cellStyle(CellStyle.head));
				
		headerList.add(row);
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		Date firstDate = DateUtil.getFirstDayOfMonth(reportDate);
		Date lastDate = DateUtil.getLastDayOfMonth(reportDate);
		List<RentEntity> list = this.stwyReportDAO.findRentByDate(firstDate,lastDate);
		for(RentEntity data : list){
			//表格填充
			row = new RowModel();
			row.addCell(new CellModel(data.getContract().getContractNum()));
			row.addCell(new CellModel(data.getContract().getCustom().getTheName()));
			row.addCell(new CellModel(DateUtil.dateToString(data.getContract().getBeginDate())+"~"+DateUtil.dateToString(data.getContract().getEndDate())));
			row.addCell(new CellModel(data.getContract().getArea()));
			row.addCell(new CellModel(data.getContract().getPrice()));
			row.addCell(new CellModel(data.getContract().getRent()));
			row.addCell(new CellModel(data.getShouldPayDate()));
			row.addCell(new CellModel(data.getPayDate()));
			row.addCell(new CellModel(data.getMoney()));
			row.addCell(new CellModel(data.getPrepayMoney()));
			row.addCell(new CellModel(data.getRepayMoney()));
			row.addCell(new CellModel(data.getLeave()));
			row.addCell(new CellModel(data.getDepositNow()));
			row.addCell(new CellModel(data.getRemark()));
			dataList.add(row);
		}
		
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;
	}

	private ReportModel getReport2(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		
		String title = "深投发展"+DateUtil.formatDate(reportDate, "yyyy年MM月")+"经营情况综述";
		String dateTag = "日期："+DateUtil.getDate();
		int colNum = 10;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).width(1000).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		
		//题注
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateTag).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		//一、物业出租情况
		row = new RowModel().rowStyle("font-weight:bold;font-size:20px;").addCell(new CellModel("一、物业出租情况").colspan(colNum).cellStyle(CellStyle.normal));
		tagList.add(row);
		//1、委托物业现状（面积：平方米）
		row = new RowModel().rowStyle("font-weight:bold;").addCell(new CellModel("1、委托物业现状（面积：平方米）").colspan(colNum).cellStyle(CellStyle.normal));
		tagList.add(row);
	
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel().addCell(new CellModel("按组分类").cellStyle(CellStyle.head).width(100).rowspan(3).colspan(2));
		row.addCell(new CellModel("物业总面积").cellStyle(CellStyle.head).width(100).rowspan(2));
		row.addCell(new CellModel("可出租物业").cellStyle(CellStyle.head).width(300).colspan(3));
		row.addCell(new CellModel("不可出租物业").cellStyle(CellStyle.head).width(300).colspan(3).rowspan(2));
		row.addCell(new CellModel("出租率（%）").cellStyle(CellStyle.head).width(200).rowspan(2));
		headerList.add(row);
		
		row = new RowModel();
		row.addCell(new CellModel("出租物业").cellStyle(CellStyle.head).width(200).colspan(2));
		row.addCell(new CellModel("空置物业").cellStyle(CellStyle.head).width(100).rowspan(2));
		headerList.add(row);
		
		row = new RowModel().addCell(new CellModel("=可出租+不可出租").cellStyle(CellStyle.head).width(100));
		row.addCell(new CellModel("已租").cellStyle(CellStyle.head).width(100));
		row.addCell(new CellModel("自用").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("问题物业").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("未建立合同物业").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("其他").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("=出租物业/（出租物业+空置）").cellStyle(CellStyle.head).width(100));
		headerList.add(row);
		
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		List<AssetEntity> datas = this.stwyReportDAO.findAssetsByGroup(reportDate);
		List<EnumDataSubEntity> groupOneList = EnumDataUtils.getEnumSubList("stwy_groupOne");
		
		List<Object[]> rowDataList = new ArrayList<Object[]>();
		Object[] rowData1 = getReport2RowData(datas,"1","1");//投资大厦
		rowDataList.add(rowData1);
		for(EnumDataSubEntity enumData : groupOneList){
			Object[] rowData = getReport2RowData(datas,enumData.getEnumDataKey(),"2");
			rowDataList.add(rowData);
		}
		Object[] sumRowData = new Object[rowData1.length];
		for(Object[] rowData : rowDataList){
			//表格填充
			row = new RowModel();
			for(Object value:rowData){
				CellModel cell = new CellModel(value);
				if(StringUtil.isDouble(value.toString())){
					cell.cellClass("rap-td-number");
				}
				row.addCell(cell);
			}
			dataList.add(row);
			//计算合并
			if(sumRowData[2]==null){
				sumRowData = rowData;
				sumRowData[0]="合计";
				sumRowData[1]="";
			}else{
				sumRowData[2]=(Double)sumRowData[2]+(Double)rowData[2];
				sumRowData[3]=(Double)sumRowData[3]+(Double)rowData[3];
				sumRowData[4]=(Double)sumRowData[4]+(Double)rowData[4];
				sumRowData[5]=(Double)sumRowData[5]+(Double)rowData[5];
				sumRowData[6]=(Double)sumRowData[6]+(Double)rowData[6];
				sumRowData[7]=(Double)sumRowData[7]+(Double)rowData[7];
				sumRowData[8]=(Double)sumRowData[8]+(Double)rowData[8];
			}
		}
		sumRowData[9]=((Double)sumRowData[3]+(Double)sumRowData[4])/((Double)sumRowData[3]+(Double)sumRowData[4]+(Double)sumRowData[5])*100;
		//合并行填充
		row = new RowModel().rowStyle("font-weight:bold;");
		for(Object value:sumRowData){
			CellModel cell = new CellModel(value);
			if(StringUtil.isDouble(value.toString())){
				cell.cellClass("rap-td-number");
			}
			row.addCell(cell);
		}
		dataList.add(row);
		//2、用途分类（面积：平方米）
		row = new RowModel().rowStyle("font-weight:bold;").addCell(new CellModel("2、用途分类（面积：平方米）").colspan(colNum).cellStyle(CellStyle.normal));
		dataList.add(row);
		//用途分类 header
		row = new RowModel().addCell(new CellModel("按用途分类").cellStyle(CellStyle.head).width(100).rowspan(3).colspan(2));
		row.addCell(new CellModel("物业总面积").cellStyle(CellStyle.head).width(100).rowspan(2));
		row.addCell(new CellModel("可出租物业").cellStyle(CellStyle.head).width(300).colspan(3));
		row.addCell(new CellModel("不可出租物业").cellStyle(CellStyle.head).width(300).colspan(3).rowspan(2));
		row.addCell(new CellModel("出租率（%）").cellStyle(CellStyle.head).width(200).rowspan(2));
		dataList.add(row);
		
		row = new RowModel();
		row.addCell(new CellModel("出租物业").cellStyle(CellStyle.head).width(200).colspan(2));
		row.addCell(new CellModel("空置物业").cellStyle(CellStyle.head).width(100).rowspan(2));
		dataList.add(row);
		
		row = new RowModel().addCell(new CellModel("=可出租+不可出租").cellStyle(CellStyle.head).width(100));
		row.addCell(new CellModel("已租").cellStyle(CellStyle.head).width(100));
		row.addCell(new CellModel("自用").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("问题物业").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("未建立合同物业").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("其他").cellStyle(CellStyle.head).width(100));
		 row.addCell(new CellModel("=出租物业/（出租物业+空置）").cellStyle(CellStyle.head).width(100));
		 dataList.add(row);
		//用途分类 data
		 List<Object[]> rowDataList2 = new ArrayList<Object[]>();
		 List<EnumDataSubEntity> useforList = EnumDataUtils.getEnumSubList("stwy_usefor");
			for(EnumDataSubEntity enumData : useforList){
				Object[] rowData = getReport2RowDataUsefor(datas,enumData.getEnumDataKey());
				rowDataList2.add(rowData);
			}
			Object[] sumRowData2 = new Object[rowData1.length];
			for(Object[] rowData : rowDataList2){
				//表格填充
				row = new RowModel();
				for(Object value:rowData){
					CellModel cell = new CellModel(value);
					if(StringUtil.isDouble(value.toString())){
						cell.cellClass("rap-td-number");
					}
					row.addCell(cell);
				}
				dataList.add(row);
				//计算合并
				if(sumRowData2[2]==null){
					sumRowData2 = rowData;
					sumRowData2[0]="合计";
					sumRowData2[1]="";
				}else{
					sumRowData2[2]=(Double)sumRowData2[2]+(Double)rowData[2];
					sumRowData2[3]=(Double)sumRowData2[3]+(Double)rowData[3];
					sumRowData2[4]=(Double)sumRowData2[4]+(Double)rowData[4];
					sumRowData2[5]=(Double)sumRowData2[5]+(Double)rowData[5];
					sumRowData2[6]=(Double)sumRowData2[6]+(Double)rowData[6];
					sumRowData2[7]=(Double)sumRowData2[7]+(Double)rowData[7];
					sumRowData2[8]=(Double)sumRowData2[8]+(Double)rowData[8];
				}
			}
			sumRowData2[9]=((Double)sumRowData2[3]+(Double)sumRowData2[4])/((Double)sumRowData2[3]+(Double)sumRowData2[4]+(Double)sumRowData2[5])*100;
			//合并行填充
			row = new RowModel().rowStyle("font-weight:bold;");
			for(Object value:sumRowData2){
				CellModel cell = new CellModel(value);
				if(StringUtil.isDouble(value.toString())){
					cell.cellClass("rap-td-number");
				}
				row.addCell(cell);
			}
			dataList.add(row);
			/*//二、物业经营情况
			row = new RowModel().rowStyle("font-weight:bold;font-size:20px;").addCell(new CellModel("二、物业经营情况").colspan(colNum).cellStyle(CellStyle.normal));
			dataList.add(row);
			//1、委托物业
			row = new RowModel().rowStyle("font-weight:bold;").addCell(new CellModel("1、委托物业").colspan(colNum).cellStyle(CellStyle.normal));
			dataList.add(row);
		
			//表头
			row = new RowModel().addCell(new CellModel("按组分类").cellStyle(CellStyle.head).width(100).rowspan(2).colspan(2));
			row.addCell(new CellModel("合同规定下月租金").cellStyle(CellStyle.head).width(100).rowspan(2));
			row.addCell(new CellModel("合同规定当月租金").cellStyle(CellStyle.head).width(300).rowspan(2));
			row.addCell(new CellModel("当月实收").cellStyle(CellStyle.head).width(300).colspan(4));
			row.addCell(new CellModel("尚欠租金").cellStyle(CellStyle.head).width(100).rowspan(2));
			row.addCell(new CellModel("截止至本月底累计实收达到本年预算的比例(%)").cellStyle(CellStyle.head).width(100).rowspan(2));
			dataList.add(row);
			
			row = new RowModel();
			row.addCell(new CellModel("合同规定当月租金").cellStyle(CellStyle.head));
			row.addCell(new CellModel("补交历史租金").cellStyle(CellStyle.head));
			row.addCell(new CellModel("预收租金").cellStyle(CellStyle.head));
			row.addCell(new CellModel("本月交租赁保证金").cellStyle(CellStyle.head));
			dataList.add(row);
			
			//数据
			List<RentEntity> rentDatas = this.stwyReportDAO.findRentByReportDate(reportDate);
			
			List<Object[]> rowDataList3 = new ArrayList<Object[]>();
			for(EnumDataSubEntity enumData : groupOneList){
				Object[] rowData = getReport2RowDataRent(datas,enumData.getEnumDataKey());
				rowDataList.add(rowData);
			}
			Object[] sumRowDataRent = new Object[colNum];
			for(Object[] rowData : rowDataList){
				//表格填充
				row = new RowModel();
				for(Object value:rowData){
					CellModel cell = new CellModel(value);
					if(StringUtil.isDouble(value.toString())){
						cell.cellClass("rap-td-number");
					}
					row.addCell(cell);
				}
				dataList.add(row);
				//计算合并
				if(sumRowData[2]==null){
					sumRowData = rowData;
					sumRowData[0]="合计";
					sumRowData[1]="";
				}else{
					sumRowData[2]=(Double)sumRowData[2]+(Double)rowData[2];
					sumRowData[3]=(Double)sumRowData[3]+(Double)rowData[3];
					sumRowData[4]=(Double)sumRowData[4]+(Double)rowData[4];
					sumRowData[5]=(Double)sumRowData[5]+(Double)rowData[5];
					sumRowData[6]=(Double)sumRowData[6]+(Double)rowData[6];
					sumRowData[7]=(Double)sumRowData[7]+(Double)rowData[7];
					sumRowData[8]=(Double)sumRowData[8]+(Double)rowData[8];
				}
			}
			sumRowData[9]=((Double)sumRowData[3]+(Double)sumRowData[4])/((Double)sumRowData[3]+(Double)sumRowData[4]+(Double)sumRowData[5])*100;
			//合并行填充
			row = new RowModel().rowStyle("font-weight:bold;");
			for(Object value:sumRowData){
				CellModel cell = new CellModel(value);
				if(StringUtil.isDouble(value.toString())){
					cell.cellClass("rap-td-number");
				}
				row.addCell(cell);
			}
			dataList.add(row);*/
			
			
			
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;
	}
	private Object[] getReport2RowDataUsefor(List<AssetEntity> datas,
			String usefor) {
		Object[] rowData = new Object[10];
		rowData[0] = EnumDataUtils.getEnumValue(usefor, "stwy_usefor");
		rowData[1] = "";
		Double hasRent=0d;
		Double self=0d;
		Double nullArea=0d;
		Double quetion=0d;
		Double noContract=0d;
		Double other=0d;
		
		Double total = 0d;
		Double percent = 0d;
		for(int i=0;i<datas.size();i++){
			AssetEntity asset = datas.get(i);
			if(asset.getUsefor().equals(usefor)){
				if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_RENT)){
					hasRent=hasRent+asset.getArea();
				}else if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_SELF)){
					self=self+asset.getArea();
				}else if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_NULL)){
					nullArea=nullArea+asset.getArea();
				}else if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_CANNOTRENT)){
					if(asset.getCanNotRentType()==null){
						other = other + asset.getArea();
					}else
					if(asset.getCanNotRentType().equals("1")){//问题物业
						quetion = quetion + asset.getArea();
					} else if(asset.getCanNotRentType().equals("2")){//未建立合同物业
						noContract = noContract + asset.getArea();
					} else if(asset.getCanNotRentType().equals("3")){//其他物业
						other = other + asset.getArea();
					} 
				}
			}
		}
		total  = hasRent+self+nullArea+quetion+noContract+other;
		if((hasRent+self+nullArea)==0){
			percent=0.0d;
		}else{
			percent = (hasRent+self)/(hasRent+self+nullArea)*100;
		}
		rowData[2] = total;
		rowData[3] = hasRent;
		rowData[4] = self;
		rowData[5] = nullArea;
		rowData[6] = quetion;
		rowData[7] = noContract;
		rowData[8] = other;
		rowData[9] = percent;
		return rowData;
	}

	/**
	 * 获取报表2中一行的数据
	 * @param datas
	 * @param string
	 * @param string2
	 * @return
	 */
	private Object[] getReport2RowData(List<AssetEntity> datas, String groupOne,
			String groupTwo) {
		Object[] rowData = new Object[10];
		rowData[0] = EnumDataUtils.getEnumValue(groupOne, "stwy_groupOne");
		rowData[1] = EnumDataUtils.getEnumValue(groupTwo, "stwy_groupTwo");
		Double hasRent=0d;
		Double self=0d;
		Double nullArea=0d;
		Double quetion=0d;
		Double noContract=0d;
		Double other=0d;
		
		Double total = 0d;
		Double percent = 0d;
		for(int i=0;i<datas.size();i++){
			AssetEntity asset = datas.get(i);
			if(asset.getGroupOne().equals(groupOne)&&asset.getGroupTwo().equals(groupTwo)){
				if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_RENT)){
					hasRent=hasRent+asset.getArea();
				}else if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_SELF)){
					self=self+asset.getArea();
				}else if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_NULL)){
					nullArea=nullArea+asset.getArea();
				}else if(asset.getAssetState().equals(AssetEntity.ASSET_STATUS_CANNOTRENT)){
					if("1".equals(asset.getCanNotRentType())){//问题物业
						quetion = quetion + asset.getArea();
					} else if("2".equals(asset.getCanNotRentType())){//未建立合同物业
						noContract = noContract + asset.getArea();
					} else if("3".equals(asset.getCanNotRentType())){//其他物业
						other = other + asset.getArea();
					} else{
						other = other + asset.getArea();
					}
				}
			}
		}
		total  = hasRent+self+nullArea+quetion+noContract+other;
		if((hasRent+self+nullArea)==0){
			percent=0.0d;
		}else{
			percent = (hasRent+self)/(hasRent+self+nullArea)*100;
		}
		rowData[2] = total;
		rowData[3] = hasRent;
		rowData[4] = self;
		rowData[5] = nullArea;
		rowData[6] = quetion;
		rowData[7] = noContract;
		rowData[8] = other;
		rowData[9] = percent;
		return rowData;
	}
	/**
	 * 物业台帐
	 * @param parameterMap
	 * @return
	 */
	private ReportModel getReport1(Map parameterMap) {
		Date reportDate;
		try{
			String dateStr= ((String[])parameterMap.get("reportDate"))[0];
			reportDate = DateUtil.strToDate(dateStr);
			if(reportDate==null){
				reportDate = new Date();
			}
		}catch(Exception e){
			reportDate = new Date();
		}
		String title = "物业台帐";
		String dateTag = "日期："+DateUtil.dateToString(reportDate);
		int colNum = 11;
		//标题
		ReportModel reportModel = new ReportModel();
		CellModel titleCell = new CellModel(title).colspan(colNum).width(1000).cellStyle(CellStyle.title);
		reportModel.setReportTitle(titleCell);
		//题注 日期
		List<RowModel> tagList = new ArrayList<RowModel>();
		RowModel row = new RowModel().rowStyle("height:20px;").addCell(new CellModel(dateTag).colspan(colNum).cellStyle(CellStyle.tag));
		tagList.add(row);
		//表头
		List<RowModel> headerList = new ArrayList<RowModel>();
		row = new RowModel().addCell(new CellModel("合同编号").cellStyle(CellStyle.head).width(50));
		row.addCell(new CellModel("承租人").cellStyle(CellStyle.head));
		row.addCell(new CellModel("合同有效期").cellStyle(CellStyle.head));
		row.addCell(new CellModel("免租期").cellStyle(CellStyle.head));
		row.addCell(new CellModel("租金单价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("政府指导价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("市场指导价").cellStyle(CellStyle.head));
		row.addCell(new CellModel("合同月租金").cellStyle(CellStyle.head));
		row.addCell(new CellModel("实收月租金").cellStyle(CellStyle.head));
		row.addCell(new CellModel("租赁保证金").cellStyle(CellStyle.head));
		row.addCell(new CellModel("备注").cellStyle(CellStyle.head));
		headerList.add(row);
		//数据
		List<RowModel> dataList = new ArrayList<RowModel>();
		List<ContractEntity> list = this.stwyReportDAO.findContracts(reportDate);
		int i =0;
		for(ContractEntity data : list){
			i = i+1;
			//表格填充
			row = new RowModel();
			row.addCell(new CellModel(data.getContractNum()).cellClass("center"));
			row.addCell(new CellModel(data.getCustom().getTheName()));
			row.addCell(new CellModel(DateUtil.dateToString(data.getBeginDate())+"~"+DateUtil.dateToString(data.getEndDate())));
			row.addCell(new CellModel(" "));
			row.addCell(new CellModel(data.getPrice()).cellClass("rap-td-number"));
			double gov = data.getGovPrice()==null?0:data.getGovPrice();
			row.addCell(new CellModel(gov).cellClass("rap-td-number"));
			row.addCell(new CellModel(data.getMarketPrice()));
			row.addCell(new CellModel(data.getRent()).cellClass("rap-td-number"));
			row.addCell(new CellModel("0").cellClass("rap-td-number"));
			row.addCell(new CellModel(data.getDeposit()).cellClass("rap-td-number"));
			row.addCell(new CellModel(data.getRemark()));
			dataList.add(row);
		}
		reportModel.setTagList(tagList);
		reportModel.setHeaderList(headerList);
		reportModel.setDataList(dataList);
		return reportModel;
	}

}
